package com.jeasonzhao.report.vml.base;

import com.jeasonzhao.report.vml.enums.ArrowTypes;
import com.jeasonzhao.report.vml.enums.DashStyles;
import com.jeasonzhao.report.vml.enums.StrokeStyles;


public class Line extends BaseElement
{
    private Vector2D m_attr_from = null;
    private Vector2D m_attr_To = null;
    public Line()
    {
    }

    public Line(Vector2D from,Vector2D to)
    {
        m_attr_from = from;
        m_attr_To = to;
    }

    public Line(int x1,int y1,int x2,int y2)
    {
        m_attr_from = new Vector2D(x1,y1);
        m_attr_To = new Vector2D(x2,y2);
    }

    public static Line HorizonLine(Vector2D pt,int nLength)
    {
        return new Line(new Vector2D(pt.getX(),pt.getY()),
                        new Vector2D(pt.getX() + nLength,pt.getY()));
    }

    public static Line HorizonLine(Vector2D pt,int nLength,int nZIndex,Color clr)
    {
        Line l = new Line(new Vector2D(pt.getX(),pt.getY()),
                          new Vector2D(pt.getX() + nLength,pt.getY()));
        l.setZIndex(nZIndex);
        l.setStrokeColor(clr);
        return l;
    }

    public static Line VerticalLine(Vector2D pt,int nLength)
    {
        Line l = new Line(new Vector2D(pt.getX(),pt.getY()),
                          new Vector2D(pt.getX(),pt.getY() + nLength));
        return l;

    }

    public static Line VerticalLine(Vector2D pt,int nLength,int nZIndex,Color clr)
    {
        Line l = new Line(new Vector2D(pt.getX(),pt.getY()),
                          new Vector2D(pt.getX(),pt.getY() + nLength));
        l.setZIndex(nZIndex);
        l.setStrokeColor(clr);
        return l;

    }

    public Vector2D getFrom()
    {
        return m_attr_from;
    }

    public Vector2D getTo()
    {
        return m_attr_To;
    }

    public void setFrom(Vector2D beginPoint)
    {
        this.m_attr_from = new Vector2D(beginPoint);
    }

    public void setTo(Vector2D endPoint)
    {
        this.m_attr_To = new Vector2D(endPoint);
    }

    public void setBeginArrow(ArrowTypes type)
    {
        Stroke st = (Stroke)this.getSubVmlElement(Stroke.class);
        boolean bNew = null == st;
        if(null == st)
        {
            st = new Stroke();
        }
        st.setBeginArrow(type);
        if(bNew)
        {
            this.addSubVmlElement(st);
        }
    }

    public void setEndArrow(ArrowTypes type)
    {
        Stroke st = (Stroke)this.getSubVmlElement(Stroke.class);
        boolean bNew = null == st;
        if(null == st)
        {
            st = new Stroke();
        }
        st.setEndArrow(type);
        if(bNew)
        {
            this.addSubVmlElement(st);
        }
    }

    public void setDashStyle(DashStyles style)
    {
        Stroke st = (Stroke)this.getSubVmlElement(Stroke.class);
        boolean bNew = null == st;
        if(null == st)
        {
            st = new Stroke();
        }
        st.setDashStyle(style);
        if(bNew)
        {
            this.addSubVmlElement(st);
        }

    }

    public void setFrom(int i,int i1)
    {
        setFrom(new Vector2D(i,i1));
    }

    public void setTo(int i,int i1)
    {
        setTo(new Vector2D(i,i1));
    }

    public static void main(String[] argvs)
        throws Exception
    {
        Line line = new Line(new Vector2D(0,0),new Vector2D(100,100));
        line.setBeginArrow(ArrowTypes.Open);
        line.setStrokeStyles(StrokeStyles.ThinThin);
        System.out.println(line.getScript());
    }

}
